package conf

import (
	"log"

	"github.com/BurntSushi/toml"
	"github.com/caarlos0/env/v6"
)

// 如果配置映射成Config对象

// 从Toml格式的配置文件加载配置
func LoadConfigFromToml(FilePath string) error {
	config = NewDefaultConfig()
	_, err := toml.DecodeFile(FilePath, config)
	if err != nil {

		log.Fatalf("LoadConfigFromToml filepath %s is error, error is %s", FilePath, err)
	}
	return LoadMysql()
}

// 从环境变量加载配置
func LoadConfigFromEnv() error {
	config = NewDefaultConfig()

	err := env.Parse(config)
	if err != nil {
		return err
	}
	return LoadMysql()

}

func LoadMysql() (err error) {

	db, err = config.MySQL.getDBcon()
	if err != nil {
		panic(err)
	}
	return

}
